//
//  DownloaderTask.h
//  yuikemall
//
//  Created by yuike6 yuike6 on 12-3-1.
//  Copyright (c) 2012年 yuike. All rights reserved.
//

#import "YTask.h"
#import "DownloadRecvData.h"
/* 
 一个下载起一个任务， 不能一个任务同时去下载多个网络请求
 */

@protocol DownloaderTaskDelegate;
@interface DownloaderTask : YTask

{
    NSURLResponse *response_;   
    DownloadRecvData * recvData_; //NSMutableData *data_; 
    
	NSURL * urlString_;
	NSURLConnection *urlconnection_;
    
    id <DownloaderTaskDelegate> delegate_;
	BOOL isDownloading_;
    
    BOOL isFinish;
    
    BOOL isCancel;
    NSLock * callBackLock_;
}

@property (nonatomic, retain) NSURLResponse *response;
@property (nonatomic, retain) NSURLConnection *urlconnection;

@property (nonatomic, retain) DownloadRecvData *recvData;
@property (nonatomic, retain) NSURL *urlString;

@property (nonatomic, assign) id<DownloaderTaskDelegate> delegate;
@property (nonatomic, assign) BOOL isDownloading;

@property (nonatomic, assign) BOOL isFinish;
@property (nonatomic, assign) BOOL isCancel;

@property (nonatomic, retain) NSLock * callBackLock;

- (void) cancelDownloader;

- (void) downloadUrl:(NSString *) aURLString;
- (void) download:(NSURL *) url;
@end


@protocol DownloaderTaskDelegate <NSObject>
@optional
- (void) didTaskReceiveDataFinish: (NSData *) theData;
- (void) didTaskReceiveFilename: (NSString *) aName;
- (void) taskDataDownloadFailed: (NSString *) reason;
- (void) taskDataDownloadAtPercent: (NSNumber *) aPercent;
@end